package com.wenbai.servicelightluxurystickers.controller;

import com.wenbai.servicelightluxurystickers.entity.StickComment;
import com.wenbai.servicelightluxurystickers.entity.dto.CommentPageQueryDto;
import com.wenbai.servicelightluxurystickers.entity.vo.parentUserVO;
import com.wenbai.servicelightluxurystickers.entity.vo.userVO;
import com.wenbai.servicelightluxurystickers.service.StickCommentService;
import com.wenbai.servicelightluxurystickers.utils.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/stick/comment")
@Slf4j
public class StickCommentController {

    @Autowired
    private StickCommentService stickCommentService;

    /**
     *根据帖子id进行查询评论
     * @param commentPageQueryDto
     * @return
     */
    @PostMapping("/pageByPostId")
    public Response<List<userVO>> pageByPostId(@RequestBody CommentPageQueryDto commentPageQueryDto){
        List<userVO> userVOList = stickCommentService.pageByPostId(commentPageQueryDto);
        return Response.success(userVOList);
    }

    /**
     *根据评论id进行查询子评论
     * @return
     */
    @PostMapping("/pageByCommentId")
    public Response<List<parentUserVO>> pageByCommentId(@RequestBody CommentPageQueryDto commentPageQueryDto){
        List<parentUserVO> parentUserVOList = stickCommentService.pageByCommentId(commentPageQueryDto);
        return Response.success(parentUserVOList);
    }

    /**
     * 根据评论id删除评论
     * @param commentId
     * @return
     */
    @DeleteMapping("/delete")
    public Response<String> delete (Long commentId){
        stickCommentService.deleteByCommentId(commentId);
        return Response.success("删除成功");
    }

    /**
     * 根据帖子id和用户id进行添加评论
     * @param stickComment
     * @return
     */
    @PostMapping("/addCommentByPostId")
    public Response<String> addCommentByPostId(@RequestBody StickComment stickComment){
        stickCommentService.addCommentByPostId(stickComment);
        return Response.success("添加成功");
    }
}
